package com.hk.controller;

import com.hk.entity.Result;
import com.hk.entity.stuGrade;
import com.hk.service.StuInfoService;
import com.hk.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 成绩信息控制器
 */
@Slf4j
@RestController
public class StuInfoController {

    @Autowired
    private StuInfoService stuInfoService;

    /**
     * 获取总成绩，平均成绩，四级成绩，平均绩点，证书数量
     * @param authorization
     * @return
     * @throws Exception
     */
    @GetMapping("/gradeInfo")
    public Result gradeInfo(@RequestHeader("token") String authorization) throws  Exception{
        // 从token头中提取JWT令牌
        String token = authorization;
        // 解析JWT令牌并提取学生ID
        Map<String, Object> claims = JwtUtils.parseJWT(token);
        String stuId = (String) claims.get("stuId");
        List<stuGrade> stuGradeList = stuInfoService.getGradeInfo(stuId);
        return Result.success(stuGradeList);
    }
}
